﻿//----------------------------------------------------------------------
// <copyright file="ExtensionJobRank.cs" company="NTT DATA BEEN (China)">
// Copyright (c)2012 NTT DATA BEEN (China) Information Technology Co.,Ltd.
// </copyright>
// <author> lidawei </author>
// <summary>
// システム名称　　：
// モジュールＩＤ　：
// モジュール名称　：
// 機能概要　　　　：ExtensionJobRank类 
// 改訂履歴　　　　：
// 2012-08-01 新規 lidawei    Been0001   
// </summary>
//---------------------------------------------------------------------- 


namespace Ntt.NttData.Been.Management.SolutionA.Sync.Operator.BLL
{
    using System;
    using System.Linq;
    using Common.Data;

    /// <summary>
    /// JobRank层扩展方法
    /// </summary>
   public   static class ExtensionJobRank
    {
        
       public static  JobRank ChangeJobRank(this JobRank jobRank)
       { 
            //BD -> ABCD
            Array rankEnum = Enum.GetValues(typeof (JobRank));
            Array.Sort(rankEnum);
            Array.Reverse(rankEnum);

            JobRank maxJobRank = 
                (from int rank in rankEnum select (JobRank) rank)
                .FirstOrDefault(eRank => (jobRank & eRank) == eRank);

           return rankEnum.Cast<int>()
               .Where(rank => rank <= (int) maxJobRank)
               .Aggregate(JobRank.None, (current, rank) => current | (JobRank) rank);
       }

    }
}
